package com.zdd.ehe.controller;

import com.zdd.ehe.entity.AnalysisForecast;
import com.zdd.ehe.result.Result;
import com.zdd.ehe.service.IAnalysisForecastService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ZhuiZhu
 * @since 2023-04-20
 */
@Api(tags="分析预测模块")
@RestController
@RequestMapping("/ehe/analysisForecast")
public class AnalysisForecastController {

    @Resource
    private IAnalysisForecastService analysisForecastService;

    @ApiOperation("新增分析预测接口")
    @PostMapping("/insertAnalysisForecast")
    public Result insertAnalysisForecast(@RequestBody AnalysisForecast analysisForecast){
        if(analysisForecast == null){
            return Result.error("数据错误，新增失败");
        }
        int result = analysisForecastService.insertAnalysisForecast(analysisForecast);
        if(result != 1){
            return Result.error("新增失败");
        }
        return Result.success("新增成功");
    }

    @ApiOperation("查询分析预测接口")
    @GetMapping("/queryAnalysisForecast")
    public Result queryAnalysisForecast(){
        List<AnalysisForecast> analysisForecastList = analysisForecastService.queryAnalysisForecast();
        if(analysisForecastList.size() == 0){
            return Result.error("无数据");
        }
        return Result.success("查询成功",analysisForecastList);
    }
}
